<?php
$xtpl = new XTemplate("modules/home/customer_task.htm");
$UPLOAD = new UPLOAD();
//--
//--
$cidsub=intval($_GET['cidsub']);
//--
//--
$POST = $_POST;
if($_POST[type] == 'NEW'){	
	
	$POST['page_id']=$_POST['page_id'];
	$POST['status']=$_POST['status'];
	$POST['image'] = $UPLOAD->doUploadImage("upload/image/", 'image', '', '150', 'on');
	$POST[name]=addslashes($POST[name]);
	$POST[description]= addslashes($POST[description]);
	//--
	$DB->DBInsert('customer', $POST);
	//--
	$GUI->redir("?mod=home&act=customer");
}
//--
//--
//--
//--
elseif($_POST[type] == 'EDIT'){
	if($_FILES['image']['name'] !=''){
	 $POST['image'] = $UPLOAD->doUploadImage("upload/image/", 'image', '', '150', 'on');
	}
	$POST['status']=$_POST['status'];
	$POST['page_id']=$_POST['page_id'];
	$POST[name]=addslashes($POST[name]);
	$POST[description]= addslashes($POST[description]);
	//--
	$DB->DBUpdate('customer',$POST, "WHERE customer_id = '".$_POST[id]."'");
	//--
	//-- check image
	if($POST['delete_img'] == '1'){
	// delete_img at root
		$row = $DB->FetchData('customer','*',"WHERE customer_id='".$_POST[id]."'");	
		@unlink("../upload/image/thumb".$row['image']);
	// end	
		$sql_up="UPDATE {$DP}customer SET image='' WHERE customer_id =".$_POST[id]."";
		mysql_query($sql_up);
	}
	//-- end
	$GUI->redir("?mod=home&act=customer");
}
//--
//--
if($_GET[id] != ''){
	$row = $DB->FetchData('customer','*',"WHERE customer_id='".$_GET[id]."'");
	$row[name]=stripslashes($row[name]);
	$row[type] = 'EDIT';
	if($row['image']!==''){
		$row['show_image']='<img src="../upload/image/thumb'.$row['image'].'" border="0" width="65" height="60">';
	}
	if($row['status']=='1'){
 		$row['status']="checked";
	}		
}else{
	$row[type] = 'NEW';
	$row['status']="checked";
}
//--
$_FCKeditor = new FCKeditor("description");
$_FCKeditor->BasePath = $siteFCKeditorPath;
$_FCKeditor->Width = '95%';
$_FCKeditor->Height = '400';
$_FCKeditor->Value = stripslashes($row[description]);
//--

// show page
$rs = $DB->SQLexec("SELECT * FROM {$DP}pages WHERE status = '1'");
$row[page] = '<select name="page_id">';
	$rs_cate = $DB->SQLexec("SELECT * FROM {$DP}admin_cate WHERE parent_id = '67' ORDER BY cate_id ASC");
	while($row_cate = mysql_fetch_array($rs_cate)){
		$row[page] .='<option value="'.$row_cate[cate_id].'" id="'.$row_cate[cate_id].'">'.$row_cate[cate_name].'</option>';
		$row[cate_id]=$row_page[cate_id];
	}
	while($row_page = mysql_fetch_array($rs)){
		$row[page] .='<option value="'.$row_page[page_id].'" id="'.$row_page[page_id].'">'.$row_page[name].'</option>';
		$row[page_is]=$row_page[page_id];
	}	
$row[page] .= '</select>';

$xtpl->assign("write",$row);
//--
//--
//--
$waypathlink = '&raquo;&nbsp;<a href="?mod=home&act=customer" class="waypath">Customer Management</a>:&nbsp;'.$row[type];
$xtpl_main->assign("waypathlink",$waypathlink);
//--
//--
//--
//--
//--
//--
$save_button = $GUI->button_ren("Save","javascript: doSavecustomer();");
$xtpl->assign("save_button",$save_button);
//--
$cancel_button = $GUI->button_ren("Cancel","javascript: add('?mod=home&act=customer');");
$xtpl->assign("cancel_button",$cancel_button);
//--
//--
//--
//--
//--
//--
?>